//
//  BranchOpenPartyOrgDynamicTableViewCell.m
//  ShangHaiHuDongApp
//
//  Created by 刘应平 on 2017/6/15.
//  Copyright © 2017年 刘应平. All rights reserved.
//

#import "BranchOpenPartyOrgDynamicTableViewCell.h"
#import "HomeCommutyActivityOneView.h"
@implementation BranchOpenPartyOrgDynamicTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

/**  190  */
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        TenGrayShadowView *under = [TenGrayShadowView new];
        under.backgroundColor = [UIColor themeGrayColor];
        [self addSubview:under];
        under.sd_layout.leftEqualToView(self).bottomEqualToView(self).widthIs([UIScreen zj_screenWith]).heightIs(10 * [UIScreen zj_screenHScale]);
    }
    return self;
}

- (void)setData:(NSArray *)data{
    _data = data;
    [self addSubview:self.scrollView];
    CGFloat width = ([UIScreen zj_screenWith] - 80 * [UIScreen zj_screenWScale]) / 2;
    for (int i = 0; i < data.count; i ++) {
        HomeCommutyActivityOneView *home = [[HomeCommutyActivityOneView alloc] initWithFrame:CGRectMake(15 * [UIScreen zj_screenWScale] + (width + 15 * [UIScreen zj_screenWScale]) * i, 0, width, self.scrollView.height)];
        home.model = data[i];
        home.tag = i;
        home.userInteractionEnabled = YES;
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapClick:)];
        [home addGestureRecognizer:tap];
        [self.scrollView addSubview:home];
        home.model = data[i];
        /**  设置scrollView.contentSize   */
        self.scrollView.contentSize = CGSizeMake(CGRectGetMaxX(home.frame) + 15 * [UIScreen zj_screenWScale], self.scrollView.height);
        
    }
}

- (void)tapClick:(UITapGestureRecognizer *)tap{
    if (self.delegate) {
        [self.delegate BranchOpenPartyOrgDynamicTable_section:self.section index:tap.view.tag];
    }
}

- (UIScrollView *)scrollView{
    if (!_scrollView) {
        _scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen zj_screenWith], 180 * [UIScreen zj_screenHScale])];
        _scrollView.contentOffset = CGPointMake(0, 0);
        _scrollView.showsVerticalScrollIndicator = NO;
        _scrollView.showsHorizontalScrollIndicator = NO;
        _scrollView.pagingEnabled = NO;
        
    }
    return _scrollView;
    
}

@end
